#include "timer.h"

namespace breaking
{
	timer::timer() :m_is_runing(false)
	{
	}

	timer::~timer()
	{
	}

	void timer::start()
	{
		m_is_runing = true;
		m_start_time = std::chrono::high_resolution_clock::now();
	}

	void timer::stop()
	{
		if (m_is_runing) 
		{
			m_end_time = std::chrono::high_resolution_clock::now();
			m_is_runing = false;
		}
	}

	double timer::elapsed()
	{
		if (m_is_runing) 
		{
			return std::chrono::duration<double>(std::chrono::high_resolution_clock::now() - m_start_time).count();
		}
		else 
		{
			return std::chrono::duration<double>(m_end_time - m_start_time).count();
		}
	}

	void timer::reset()
	{
		m_is_runing = false;
	}
}

